package org.safaproject.server.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.safaproject.server.model.Rol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor=Exception.class)
public class RolDAO extends HibernateDaoSupport {
	
	@Autowired
	public void initSessionFactory(SessionFactory factory) {
	    setSessionFactory(factory);
	}
	
	public Rol getRolById(Long idRol){
		return (Rol) super.getHibernateTemplate().load(Rol.class, idRol);
	}
	
	@SuppressWarnings("unchecked")
	public List<Rol> getAllRoles(){
		return super.getHibernateTemplate().find("from Rol");
	}
	
	public Long saveRol(Rol rol){
		super.getHibernateTemplate().save(rol);
		return rol.getIdRol();
	}
	
	public Long updateRol(Rol rol){
		super.getHibernateTemplate().update(rol);
		return rol.getIdRol();
	}

}
